<div class="tableform">
  <form action="index.php?app=ome&ctl=admin_setting&act=updateSort" id="catEditor" method="post">

    <div class="finder-top clearfix">
      <div class="finder-title"><h5><{t}>售后问题类别<{/t}><em class="num"><{t}>(共<{$tree_number}>条)<{/t}></em></h5></div>
    </div>
    <div class="gridlist-action">
      <{button label="添加分类" icon="btn_add.gif" app="desktop" onclick="W.page('index.php?app=ome&ctl=admin_setting&act=addnew')" }>
      <{if $tree_number<=500}> <{button label="全部展开" id="showCat-handle" icon="btn_unfolded.gif" app="desktop" }> <{button label="全部收起" icon="btn_folded.gif" id="hideCat-handle" app="desktop" }><{/if}>
      &nbsp;
    </div>
    <div class='gridlist-head mainHead'>
      <div class='span-8' ><{t}>类别名称<{/t}></div>
      <div class='span-2'><{t}>添加子类<{/t}></div>
      <div class='span-2'><{t}>编辑<{/t}></div>
      <div class='span-2'><{t}>删除<{/t}></div>
    </div>

    <div id="cat_tree" class='gridlist'> <{foreach from=$tree item=item name="item"}>
      <div depath="<{$item.step}>" class="clear_cat row" cid="<{$item.problem_id}>" pid="<{$item.pid}>">
        <div class='row-line clearfix'>
          <div class='span-8' style='text-align:left!important'>
            <div  style="margin-left:<{$item.step*25}>px;"><{if $tree_number<=500}>
              <{if $item.cls=='true'}>  <span style='width:12px;line-height:12px;margin:auto 4px;overflow:hidden;display:inline-block;padding:0;cursor:pointer'>  <{img src="bundle/handle-hide.gif" alt="收起子分类" title="收起子分类" class="handle-hide" app='desktop'}>
                <{img src="bundle/handle-show.gif" alt="收起子分类" title="展开子分类" class="handle-show" app='desktop'}> </span> <{else}>
              <{img src="bundle/blue-dot.gif" app='desktop'}>
              <{/if}>
              <{/if}>
              <{t}>排序<{/t}>
              <input class="_x_ipt" type="number" size="2"  name="p_order[<{$item.problem_id}>]" value="<{$item.p_order|default:0}>" vtype="unsigned">
              <span class="lnk" style="color:#369; padding-right:15px;" onClick='W.page("index.php?app=ome&ctl=admin_setting&act=edit&p[0]=<{$item.problem_id}>")'><{$item.cat_name}></span></div>
          </div>
          <div class='span-2'><{assign var="problem_id" value=$item.problem_id}><span class="opt" onClick='W.page("index.php?app=ome&ctl=admin_setting&act=addnew&p[0]=<{$item.problem_id}>")'><{img src="bundle/addcate.gif" border="0" alt="添加子分类" app='desktop'}></span></div>
          <div class='span-2'><span class="opt" onClick="W.page('index.php?app=ome&ctl=admin_setting&act=edit&p[0]=<{$item.problem_id}>')"><{img src="bundle/editcate.gif" border="0" alt="编辑"  app='desktop'}></span></div>
          <div class='span-2'><span class="opt" onclick="deleteRow('index.php?app=ome&ctl=admin_setting&act=toRemove&p[0]=<{$item.problem_id}>',event)"><{img src="bundle/delecate.gif" border="0" alt="删除" app='desktop'}></span></div>
        </div>
      </div>
      <{/foreach}> </div>

  </form>
</div>
<{if $tree}>
<{area inject='.mainFoot'}>
<div class="footer">
  <div class="table-action">
    <{button class="btn-primary" label="保存排序" onclick="toSubmit()"}>
  <script>
     function toSubmit(){
    	 $('catEditor').fireEvent('submit',{stop:$empty});
     }
  </script>
  </div>
</div>
<{/area}>
<{/if}>
<script>

  function deleteRow(act,event){
    e=$(new Event(event).stop().target);
    var row=e.getParent('.row');

    if(confirm('您确定要删除该分类？')){
      W.page(act,{
        method:'get',
        update:'messagebox',
        onComplete:function(re){
          if(re.contains('successSplash')){row.remove();}
        }
      });
    }
  }
  <{if $tree_number<=500}>
  void function(){
    $E('#hideCat-handle').addEvent('click',function(){
      $ES('#cat_tree .clear_cat').each(function(e){
        if(e.get('depath')>1){
          e.setStyles({'display':'none'});
        }
      });
      $ES('#cat_tree .handle-hide').hide();
    });
    $E('#showCat-handle').addEvent('click',function(){

      $ES('#cat_tree .clear_cat').each(function(e){
        if(e.get('depath')>1){
          e.setStyles({'display':''});
        }
      });
      $ES('#cat_tree .handle-hide').show();
    });

    $('cat_tree').addEvent('click',function(e){

      if(!e.target.className.match(/handle-/i))return;

      var handle=$(e.stop().target);
      var eventRow=handle.getParent('.row');
      var visible=handle.hasClass('handle-show')?'':'none';
      if(visible=='none'){
        handle.hide().getNext().show();
        }else{
        handle.hide().getPrevious().show();

      }
      flode(eventRow,visible);

    });

    function flode(eventRow,visible){
      var cid=eventRow.get('cid');
      var pid=eventRow.get('pid');

      eventRow.getAllNext('div[pid='+cid+']').each(function(row){
        if(visible=='none'){
          row.hide();
          var obj=row.getElements('.span-8 img');
          if(obj.length>1){
            flode(row,visible);
          }
          }else{
          row.show();
          var obj=row.getElements('.span-8 img');
          if(obj.length>1){
            var vis=(obj[0].getStyle('display')=='none'?'none':'inline');
            flode(row,vis);
          }
        }

      });
    }
  }();
  <{/if}>

</script>
